using Microsoft.AspNetCore.Mvc;
using ShopForWeb.Dto.AjaxModels;
using ShopForWeb.Dto.ViewModels;
using ShopForWeb.Service;
using ShopForWeb.UI.Extensions;


namespace ShopForWeb.UI.Controllers.Admin;
[Area("admin")]
[Route("[area]/identity")]

public class IdentityController : Controller
{
  private ManagerService _service;
  public IdentityController(ManagerService service)
  {
    _service = service;
  }

  [HttpPost("login")]
  public async Task<IActionResult> GetByLogin(string phone, string password)
  {
    var mvm = await _service.GetByLoginAsync(phone, password);
    if (mvm != null)
    {
      //管理员信息存入Session
      this.HttpContext.Session.Set<ManagerViewModel>("manager", mvm);
      return Json(new ResponseAjaxModel()
      {
        Status = 0,
        Message = $"欢迎{mvm.Phone}的到来"
      });
    }
    else
    {
      return Json(new ResponseAjaxModel()
      {
        Status = 1,
        Message = "查无此人"
      });
    }
  }

  [HttpGet("login")]
  public IActionResult GetIndex()
  {
    return View();
  }
}
